Subject: Re: Help me a little. Please!
From: [email-masked]
To: [email-masked]
Date: Fri, 15 Dec 1995 12:39:49 --100

[email-masked] (Anders Nygren) wrote a plea FOR HELP ON 11.12.1995.
He also got a reply from Chris hodges, however, I have something to add.
First he asked some questions, after wich he asked the following one:

> AN> and is it possible
> AN> to redimension a variable after I already have dimensioned it?
> 
> No. For your file requester thingy, I would use a bank for the directory
> data or an array of fixed maximum size for the data.

Now, in a way Chris is correct, you cannot redimension an array after you have dimensioned it, but, look at this:

Rem Global or non global??
Rem That's the question.
Rem a simple example, by Jeroen Knoester ([email-masked])
'
Rem Global vars:
Dim array1(10,10)
Global array1()
Rem now this array can never be altered in size, but...
'
Procedure example
Rem Create an array
count=Rnd(100)
Print count
'
Dim array2(count)
Rem this array is now dimensioned, right..
Rem So.. it cannot be altered in size, right..
Rem Correct, BUT this is a LOCAL array.. If the procedure is exited
Rem and then reentered later, the main program will have forgotten all
Rem about the array, so.. It will locally redimension the array, with a
Rem different size.
'
End Proc
'
Rem Main loop
'
While inkey$=""
  example
Wend
End

This little program will show you the benefits of local vars over global ones.
What happens is this:
In the main program, the computer knows nothing about the array in the procedure
example. While inside the procedure, the array is dimensioned, with a random
size. When this procedure is exited, the computer will totally forget the
array dimensioned INSIDE the procedure. When the program then calls the procedure again, the computer will redimension the array, simply because according to the computer, the array is not there.

This poses a single problem, how to get the information you need from this procedure to the outside world..
Well, you use a single global var as help. What you do is this: 

You read the information you need from your file selector, wich is a single file. This information you stick into a global var from the main program BEFORE you
exit the procedure. This way you can redimension your array, and still get the
information you need from it.

If you need the array to be known among multiple procedures, you simply declare it as a Shared var in the other procedure to use the array, like this:

Procedure Needs_your_array
   Shared array()
   Rem code goes here..
End Proc

I hope this helps... See you,

Jeroen Knoester, [email-masked]
--Check out the Power Programs homepage at http://www.si.hhs.nl/~v942360/Amiga.html-- A500, 68000 7 Mhz!! Still running!!